package service

import (
	"iris-wms/apps/admin/web/dto/din"
	"iris-wms/apps/admin/web/dto/dout"
	"iris-wms/common/pkg/db"
	"iris-wms/common/pkg/db/dao"
)

var _ WmsReportService = (*wmsReportService)(nil)

type WmsReportService interface {
	GetByWarehouse(din.WmsReportTableIn) ([]*dout.WmsReportOfWarehouseOut, int64, error)
	GetByGoods(din.WmsReportTableIn) ([]*dout.WmsReportOfGoodsOut, int64, error)
}

func NewWmsReportService() *wmsReportService {
	return &wmsReportService{}
}

type wmsReportService struct{}

func (impl *wmsReportService) GetByWarehouse(in din.WmsReportTableIn) (rows []*dout.WmsReportOfWarehouseOut, total int64, err error) {
	q := dao.Use(db.GDB1).WmsReportOfWarehouseOut
	rows, err = q.
		Preload(q.Warehouse).
		Preload(q.Cate).
		QueryInventoryByWarehouse(in.Wid, in.GoodsId, in.Offset(), in.PageSize)
	return
}

func (impl *wmsReportService) GetByGoods(in din.WmsReportTableIn) (rows []*dout.WmsReportOfGoodsOut, total int64, err error) {
	q := dao.Use(db.GDB1).WmsReportOfGoodsOut
	rows, err = q.
		Preload(q.Warehouse).
		Preload(q.Cate).
		QueryInentoryByGoods(in.Wid, in.GoodsId, in.Offset(), in.PageSize)
	return
}
